package com.jcl.recruit.api.user.controller;

import com.jcl.core.common.page.PageResult;
import com.jcl.core.resp.ApiResponse;
import com.jcl.recruit.core.constants.Constants;
import com.jcl.recruit.user.model.User;
import com.jcl.recruit.user.service.UserService;
import com.jcl.recruit.user.vo.UserSearchEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static org.springframework.beans.support.PagedListHolder.DEFAULT_PAGE_SIZE;

/**
 * @ClassName UserCertificationController
 * @Description TODO
 * @Author yyliu
 * @Date 2018/9/12
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/user")
public class UserCertificationController {

    @Autowired
    private UserService userService;


    /* *
     * @Author yyliu
     * @Description 用户申请认证列表
     *
     * @Date 19:01 2018/9/12
     * @Param [result]
     * @return java.util.Map<java.lang.String,java.lang.Object>
     **/
    @RequestMapping(value = "/certification/list",method = RequestMethod.POST)
    public ApiResponse certificationList(@RequestBody UserSearchEntity entity){

        entity.setType(UserSearchEntity.TYPE_CERTIFY);
        PageResult result = userService.pageList(entity, entity.getToPage(), DEFAULT_PAGE_SIZE);

        return ApiResponse.success(result);
    }

    /* *
     * @Author yyliu
     * @Description 用户申请认证
     *
     * @Date 19:01 2018/9/12
     * @Param [result]
     * @return java.util.Map<java.lang.String,java.lang.Object>
     **/
    @RequestMapping(value = "/certification/status/{id}",method = RequestMethod.POST)
    public ApiResponse updateCertification(@PathVariable("id") Integer id){
        User user =  userService.findOneById(id);
        user.setStatus(Constants.UserInfo.USER_STATUS_ACTIVE);
        userService.updateByPrimaryKeySelective(user);
        return ApiResponse.success(Constants.ReturnInfo.SUCCESS_MSG);
    }

}
